const mysql      = require('mysql');

module.exports=(sql,params)=>{
    //配置数据库
    const connection = mysql.createConnection({
        host     : 'localhost',
        user     : 'root',
        password : 'root',
        database : '1711b'
    });
    //连接数据库
    connection.connect((error)=>{
        if(error) throw error 
        console.log('mysql is connected....')
    });
    
    return new Promise((resolve, reject) => {
        //查询数据库
        connection.query(sql,params, (error, results, fields)=>{
             if(error) return reject(error)
             resolve(results)
        });
        
        connection.end();
    })
    
}